package com.ryskoo.framework.core.utils;

import com.ryskoo.customer.vendor.domain.VendorPO;
import com.ryskoo.customer.vendormanager.domain.VendorManagerPO;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

public class LoginUtil {

	/** 当前登录的用户(会员/员工) */
	public static final String LOGIN_USER = "login_user";

	/** 商户登录后，保存主商户信息 */
	public static final String LOGIN_VENDOR = "login_vendor";

	public static String getLoginUserUuid() {
		try {
			 VendorManagerPO po = (VendorManagerPO)getLoginUserModel();
			 return po.getUuid();
		} catch (Exception err) {
			err.printStackTrace();
		}
		return "";
	}

	public static <T> T getLoginUserModel() {
		try {
			Subject subject = SecurityUtils.getSubject();
			return (T) subject.getSession().getAttribute(LOGIN_USER);
		} catch (Exception err) {
			err.printStackTrace();
		}
		return null;
	}

	public static String getLoginVendorUuid() {
		try {
			 VendorPO po = (VendorPO)getLoginVendorModel();
			 return po.getUuid();
		} catch (Exception err) {
			err.printStackTrace();
		}
		return "";
	}

	public static <T> T getLoginVendorModel() {
		try {
			Subject subject = SecurityUtils.getSubject();
			return (T) subject.getSession().getAttribute(LOGIN_VENDOR);
		} catch (Exception err) {
			err.printStackTrace();
		}
		return null;
	}

}
